import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @Author wonghiu
 * @Date 2021/7/5 14:56
 * @Version 1.0.1
 */
public class shopeey {


    public static void main(String[] args) {
        Solution solution = new shopeey().new Solution();
        int[][] rooms = new int[][]{{-2,-3,3},{-5,-10,1},{10,30,-5}};

        for (int i = 0; i < rooms.length; i++) {
            System.out.println(Arrays.toString(rooms[i]));
        }
        int[] start = new int[]{0,0};
        int[] end = new int[]{2,2};
//        System.out.println(solution.minimumInitHealth(rooms,start,end));
//        [[100]],[0,0],[0,0]
        System.out.println(solution.minimumInitHealth(new int[][]{{100}},new int[]{0,0},new int[]{0,0}));

//        String s = "shhhopeeeew";
//        String res="";
//        for (int i = 0; i < s.length(); i++) {
//            res+=s.charAt(i);
//            int count = 1;
//            while (i+1<s.length() && s.charAt(i+1)==s.charAt(i)){
//                i++;
//                count++;
//            }
//            if (count==1){
//                continue;
//            }else {
//                res+=count;
//            }
//        }
//        System.out.println(res);
    }

    class Solution {
        public int totalScore = 0;
        public int curMaxNeedScore = 1;
        public int minNeedScore = Integer.MAX_VALUE;

        public int minimumInitHealth(int[][] rooms, int[] startPoint, int[] endPoint) {
            // write code here
            int[][] visit = new int[rooms.length][rooms[0].length];
            dfs(rooms, 0, 0, visit);
            return minNeedScore;
        }

        public void dfs(int[][] rooms, int i, int j, int[][] visit) {
            if (i < 0 || j < 0 || i >= rooms.length || j >= rooms[0].length || visit[i][j] == 1) {
                return;
            }
            visit[i][j] = 1;
            totalScore += rooms[i][j];
            int temp = curMaxNeedScore;

            curMaxNeedScore = Math.max(curMaxNeedScore,1 - totalScore);
            if (i == rooms.length - 1 && j == rooms[0].length - 1) {
                if (curMaxNeedScore < minNeedScore) {
                    minNeedScore = curMaxNeedScore;
                }
            }
            dfs(rooms, i - 1, j, visit);
            dfs(rooms, i + 1, j, visit);
            dfs(rooms, i, j - 1, visit);
            dfs(rooms, i, j + 1, visit);
            curMaxNeedScore = temp;
            totalScore -= rooms[i][j];
            visit[i][j] = 0;

        }
    }
}
